Load libaries and data
packages <- c("tidyverse", "lubridate", "geofacet", "DT")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org")
}
library(tidyverse)
library(lubridate)
library(geofacet)
library(DT)
ff <- read_csv("https://github.com/washingtonpost/data-police-shootings/raw/master/fatal-police-shootings-data.csv")
Do your analysis
ff_state_annual <- ff %>%
mutate(year=year(date)) %>%
count(year, state, name="total")
ff_state_annual %>%
filter(year!=2021) %>%
ggplot(aes(x=year, y=total)) +
geom_col() +
theme_minimal() +
facet_geo(~state, scale="free_y") +
labs(title="Police shootings over time",
caption="Data: The Washington Post")

ff_state_annual %>%
pivot_wider(names_from="year", values_from="total") %>%
datatable(extensions = 'Buttons',
options = list(dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel','pdf')))